package com.xuan.webfinally.service.impl;

import com.xuan.webfinally.entity.DefineEquip;
import com.xuan.webfinally.entity.EquipmentStatisticsResponse;
import com.xuan.webfinally.entity.LabelValueDTO;
import com.xuan.webfinally.entity.MonitoringRequest;
import com.xuan.webfinally.entity.SensorDataDTO;
import com.xuan.webfinally.entity.SlopeCrackData;
import com.xuan.webfinally.mapper.SlopeCrackDataMapper;
import com.xuan.webfinally.service.ISlopeCrackDataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 边坡裂缝传感器监测数据表 服务实现类
 * </p>
 *
 * @author gyuxuan
 * @since 2025-05-18
 */
@Service
public class SlopeCrackDataServiceImpl extends ServiceImpl<SlopeCrackDataMapper, SlopeCrackData> implements ISlopeCrackDataService {

    @Autowired
    private SlopeCrackDataMapper slopeCrackDataMapper;

    @Override
    public List<LabelValueDTO> getLineDataOne(Long deptId) {
        return slopeCrackDataMapper.getListData(deptId);
    }

    @Override
    public Map<String, Object> getStatistics(MonitoringRequest request) {
        int total = 50;

        List<EquipmentStatisticsResponse> list = new ArrayList<>();

        for (int i = 0; i < request.getSize(); i++) {
            EquipmentStatisticsResponse item = new EquipmentStatisticsResponse();
            item.setTitle("倾斜_JC_ZDJGWQX_0" + ((request.getPage() - 1) * request.getSize() + i + 1));
            item.setTime("2025-01-11 06:13:00");
            // 封装成类，从而接收
            List<DefineEquip> dataTo = slopeCrackDataMapper.getDataTo();
            List<EquipmentStatisticsResponse.DataPoint> dataPoints = List.of(
                    new EquipmentStatisticsResponse.DataPoint("X方向角度", "2.35°"),
                    new EquipmentStatisticsResponse.DataPoint("Y方向角度", "0.41°"),
                    new EquipmentStatisticsResponse.DataPoint("Z方向角度", "87.62°"),
                    new EquipmentStatisticsResponse.DataPoint("XY倾角", "0.5°"),
                    new EquipmentStatisticsResponse.DataPoint("方位角", "0.5°"),
                    new EquipmentStatisticsResponse.DataPoint("累计降雨量", "0mm"),
                    new EquipmentStatisticsResponse.DataPoint("小时降雨量", "0.75mm"),
                    new EquipmentStatisticsResponse.DataPoint("日降雨量", "10mm"),
                    new EquipmentStatisticsResponse.DataPoint("裂缝累计量", "5.13mm"),
                    new EquipmentStatisticsResponse.DataPoint("x轴加速度", "0.01"),
                    new EquipmentStatisticsResponse.DataPoint("y轴加速度", "0.42"),
                    new EquipmentStatisticsResponse.DataPoint("z轴加速度", "-0.34")
            );

            item.setData(dataPoints);
            list.add(item);
        }

        Map<String, Object> result = new HashMap<>();
        result.put("total", total);
        result.put("list", list);

        return result;
    }

    @Override
    public List<SensorDataDTO> getDeviceStatisticsNew() {
        List<SensorDataDTO> list = new ArrayList<>();
//        list = slopeCrackDataMapper.getDeviceStatisticsNew();
        return slopeCrackDataMapper.getDeviceStatisticsNew();
    }
}
